<?php
error_reporting(E_ALL ^ E_NOTICE);

set_time_limit(0);
$conn = @mysql_connect("localhost","root","root");
if (!$conn){
    die("Could not connect：" . mysql_error());
}

mysql_select_db("comds", $conn);
mysql_query("set names 'UTF-8'"); 
 
$deviceid_query =  mysql_query("SELECT DISTINCT deviceid,FirstLogin FROM comds where Cracked = '0'");

while($deviceid = mysql_fetch_array($deviceid_query))
{
     //进入游戏次数
    $playNum_query = mysql_query("SELECT count(1) FROM comds where deviceid = '$deviceid[deviceid]'");

    $playNum = mysql_fetch_array($playNum_query);

     //总游戏时间
    $TotalGameTime_query = mysql_query("SELECT TotalGameTime FROM comds_last where deviceid = '$deviceid[deviceid]'");
    $TotalGameTime = mysql_fetch_array($TotalGameTime_query);

    //最后停留等级
    $level_query = mysql_query("SELECT Level FROM comds_last where deviceid = '$deviceid[deviceid]'");
    $level = mysql_fetch_array($level_query);

    //成活率 Survival
    $Survival_query = mysql_query("SELECT  count(1)
FROM comds
WHERE Cracked = '0' and date > DATE_ADD( '$deviceid[FirstLogin]', INTERVAL 7
DAY )
and  deviceid = '$deviceid[deviceid]'");
    $Survival = mysql_fetch_array($Survival_query);
         //099cents1 购买次数
    $_099cents1_query = mysql_query("SELECT sum(099cents1) FROM comds where deviceid = '$deviceid[deviceid]'");
    $_099cents1 = mysql_fetch_array($_099cents1_query);
        //099cents2 购买次数
    $_099cents2_query = mysql_query("SELECT sum(099cents2) FROM comds where deviceid = '$deviceid[deviceid]'");
    $_099cents2 = mysql_fetch_array($_099cents2_query);
        //new499cents1 购买次数
    $_new499cents1_query = mysql_query("SELECT sum(new499cents1) FROM comds where deviceid = '$deviceid[deviceid]'");
    $_new499cents1 = mysql_fetch_array($_new499cents1_query);
        //new499cents2 购买次数
    $_new499cents2_query = mysql_query("SELECT sum(new499cents2) FROM comds where deviceid = '$deviceid[deviceid]'");
    $_new499cents2 = mysql_fetch_array($_new499cents2_query);
        //new999cents1 购买次数
    $_new999cents1_query = mysql_query("SELECT sum(new999cents1) FROM comds where deviceid = '$deviceid[deviceid]'");
    $_new999cents1 = mysql_fetch_array($_new999cents1_query);
        //new999cents2 购买次数
    $_new999cents2_query = mysql_query("SELECT sum(new999cents2) FROM comds where deviceid = '$deviceid[deviceid]'");
    $_new999cents2 = mysql_fetch_array($_new999cents2_query);
        //new1999cents1 购买次数
    $_new1999cents1_query = mysql_query("SELECT sum(new1999cents1) FROM comds where deviceid = '$deviceid[deviceid]'");
    $_new1999cents1 = mysql_fetch_array($_new1999cents1_query);
        //new1999cents2 购买次数
    $_new1999cents2_query = mysql_query("SELECT sum(new1999cents2) FROM comds where deviceid = '$deviceid[deviceid]'");
    $_new1999cents2 = mysql_fetch_array($_new1999cents2_query);
        //new4999cents1 购买次数
    $_new4999cents1_query = mysql_query("SELECT sum(new4999cents1) FROM comds where deviceid = '$deviceid[deviceid]'");
    $_new4999cents1 = mysql_fetch_array($_new4999cents1_query);   
     //new4999cents2 购买次数
    $_new4999cents2_query = mysql_query("SELECT sum(new4999cents2) FROM comds where deviceid = '$deviceid[deviceid]'");
    $_new4999cents2 = mysql_fetch_array($_new4999cents2_query);

    var_dump($playNum[0]);
 
$sql = "UPDATE report_nojailbreak_total SET playNum= '$playNum[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql2 = "UPDATE report_nojailbreak_total SET TotalGameTime= '$TotalGameTime[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql3 = "UPDATE report_nojailbreak_total SET Survival= '$Survival[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql4 = "UPDATE report_nojailbreak_total SET level= '$level[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql5 = "UPDATE report_nojailbreak_total SET 099cents1= '$_099cents1[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql6 = "UPDATE report_nojailbreak_total SET 099cents2= '$_099cents2[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql7 = "UPDATE report_nojailbreak_total SET new499cents1= '$_new499cents1[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql8 = "UPDATE report_nojailbreak_total SET new499cents2= '$_new499cents2[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql9 = "UPDATE report_nojailbreak_total SET new999cents1= '$_new999cents1[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql10 = "UPDATE report_nojailbreak_total SET new999cents2= '$_new999cents2[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql11 = "UPDATE report_nojailbreak_total SET new1999cents1= '$_new1999cents1[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql12 = "UPDATE report_nojailbreak_total SET new1999cents2= '$_new1999cents2[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql13 = "UPDATE report_nojailbreak_total SET new4999cents1= '$_new4999cents1[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql14 = "UPDATE report_nojailbreak_total SET new4999cents2= '$_new4999cents2[0]' WHERE deviceid= '$deviceid[deviceid]'";

if(mysql_query($sql,$conn)){
    echo "1 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql2,$conn)){
    echo "2 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql3,$conn)){
    echo "3 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql4,$conn)){
    echo "4 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql5,$conn)){
    echo "5 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql6,$conn)){
    echo "6 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql7,$conn)){
    echo "7 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql8,$conn)){
    echo "8 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql9,$conn)){
    echo "9 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql10,$conn)){
    echo "10 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql11,$conn)){
    echo "11 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql12,$conn)){
    echo "12 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql13,$conn)){
    echo "13 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql14,$conn)){
    echo "14 update is ok!";
} else {
    echo "failed：".mysql_error();
}

}
?>
